package model

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
	"practice/config"
	"time"
)

type Article struct {
	ID        uint       `gorm:"primary_key" json:"id"`
	Title     string     `gorm:"size:50" json:"title"`
	Desc      string     `gorm:"type:text" json:"desc"`
	Birthday  time.Time  `json:"birthday"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `sql:"index" json:"deleted_at"`
}

func init() {
	db, err := gorm.Open(config.MysqlDB["type"], config.ConnectionString)
	if err != nil {
		panic(err)
	}
	defer db.Close()
	// 关闭表名复数
	db.SingularTable(config.SingularTable)
	db.AutoMigrate(&Article{})
}
